package database;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.UniqueConstraint;

import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * This class represent Supermarket for Hibernate ORM Library
 * @author Moshe Ronen, Lior Bunzl
 *
 */
@Entity
@Table(name = "SUPERMARKET", catalog = "telhai", uniqueConstraints = {
		@UniqueConstraint(columnNames = {"SUPERMARKET_NAME","SUPERMARKET_BRANCH","SUPERMARKET_LOCATION_LATITUDE","SUPERMARKET_LOCATION_LONGITUDE"})})
public class Supermarket implements Serializable
{
	private static final long serialVersionUID = 1L;
	private Integer supermarketId;
	private String supermarketName;
	private String supermarketBranch;
	private Double supermarketLocationLatitude;
	private Double supermarketLocationLongitude;
	private Set<ProductSupermarket> productSupermarkets = new HashSet<ProductSupermarket>(0);
	
	public Supermarket()
	{}
	
	public Supermarket(String supermarketName, String supermarketBranch, Double supermarketLocationLatitude, Double supermarketLocationLongitude)
	{
		this.supermarketName = supermarketName;
		this.supermarketBranch = supermarketBranch;
		this.supermarketLocationLatitude = supermarketLocationLatitude;
		this.supermarketLocationLongitude = supermarketLocationLongitude;
	}
	
	public Supermarket(String supermarketName, String supermarketBranch, Double supermarketLocationLatitude, Double supermarketLocationLongitude, Set<ProductSupermarket> productSupermarkets)
	{
		this.supermarketName = supermarketName;
		this.supermarketBranch = supermarketBranch;
		this.supermarketLocationLatitude = supermarketLocationLatitude;
		this.supermarketLocationLongitude = supermarketLocationLongitude;
		this.productSupermarkets = productSupermarkets;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "SUPERMARKET_ID", unique = true, nullable = false)
	public Integer getSupermarketId()
	{
		return this.supermarketId;
	}

	public void setSupermarketId(Integer supermarketId)
	{
		this.supermarketId = supermarketId;
	}

	@Column(name = "SUPERMARKET_NAME", unique = false, nullable = false, length = 50)
	public String getSupermarketName()
	{
		return this.supermarketName;
	}

	public void setSupermarketName(String supermarketName)
	{
		this.supermarketName = supermarketName;
	}

	@Column(name = "SUPERMARKET_BRANCH", unique = false, nullable = false, length = 255)
	public String getSupermarketBranch()
	{
		return this.supermarketBranch;
	}

	public void setSupermarketBranch(String supermarketBranch)
	{
		this.supermarketBranch = supermarketBranch;
	}
	
	@Column(name = "SUPERMARKET_LOCATION_LATITUDE", unique = false, nullable = false)
	public Double getSupermarketLocationLatitude()
	{
		return this.supermarketLocationLatitude;
	}

	public void setSupermarketLocationLongitude(Double supermarketLocationLongitude)
	{
		this.supermarketLocationLongitude = supermarketLocationLongitude;
	}
	
	@Column(name = "SUPERMARKET_LOCATION_LONGITUDE", unique = false, nullable = false)
	public Double getSupermarketLocationLongitude()
	{
		return this.supermarketLocationLongitude;
	}

	public void setSupermarketLocationLatitude(Double supermarketLocationLatitude)
	{
		this.supermarketLocationLatitude = supermarketLocationLatitude;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.supermarket")
	public Set<ProductSupermarket> getProductSupermarkets()
	{
		return this.productSupermarkets;
	}

	public void setProductSupermarkets(Set<ProductSupermarket> productSupermarkets)
	{
		this.productSupermarkets = productSupermarkets;
	}
	
	@Override
	public String toString()
	{
	    return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
	    .append("Id", supermarketId)
	    .append("Name", supermarketName)
	    .append("Location Latitude", supermarketLocationLatitude)
	    .append("Location Longitude", supermarketLocationLongitude)
	    .toString();
	}
}
